{% extends 'blank.html.twig' %}
{% block body %}
    <div>
        <span>加密文字：</span>
        <input id="textinfo" type="text" value="">
        <span>秘钥：</span>
        <input id="secrectinfo" type="text" value="">
        <button class="uploadify-button" onclick="Encrypt()">js前端加密</button>
    </div>
    <span>加密后的字符串：</span>
    <div id="showencrypt"></div>
    <span>php后端解密的字符串：</span>
    <div id="showdecrypt"></div>
{% endblock %}
{% block footer %}
    <script type="text/javascript" src="/AbsSR/web/static/common/js/aes/aes.js"></script>
    <script type="text/javascript" src="/AbsSR/web/static/huiadmin/lib/jquery/1.9.1/jquery.js"></script>
    <script type="text/javascript" src="/AbsSR/web/static/common/js/aes/aes-json-format.js"></script>
    <script type="text/javascript">

        //js加密函数
        function Encrypt(){
            //获取被加密字符串
            var _strTextInfo = $('#textinfo').val();
            //获取加密秘钥
            var _strSecrectInfo = $('#secrectinfo').val();
            var _strEncryptText = CryptoJS.AES.encrypt(_strTextInfo,_strSecrectInfo,{format: CryptoJSAesJson}).toString();
            $('#showencrypt').html(_strEncryptText);
            console.log($('#showencrypt').html());
            ApiRequest();
        }
        //将js加密后的字符串传递到后台解密之后传输之后显示在前端页面上
        function ApiRequest(){
            $.ajax({
                type:'POST',
                url:'{{ path('endecrypt_test') }}',
                data:{
                    encrypttext:$('#showencrypt').html()
                },
                success:function(msg){
                    $('#showdecrypt').html(msg);
                }
            });
        }
    </script>
{% endblock %}